<template>
	<view>
		<view class="edgeInsetTop"></view>
		<view class="cu-form-group">
			<view class="title">姓名</view>
			<input type="text" placeholder="姓名" v-model="name"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">用户手机号</view>
			<input type="number" placeholder="手机号码" maxlength="11" v-model="mobile"></input>
		</view>

		<view class="padding-bj flex flex-direction margin-top" style="margin-top: 58%;">
			<button @tap="confirm" class="cu-btn wanl-bg-orange lg">提交申请</button>
		</view>
		<!-- <view class="" style="    height: 300px;
    margin: 0 15px;
    width: 90%;
    word-wrap: break-word; word-break:break-all; overflow: hidden;">
			xx{{option}}
		</view> -->
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		computed: {
			// ...mapState(['user'])
		},
		data() {
			return {
				mobile: '',
				name: '',
				option: ''
			}
		},
		onLoad(e) {
			if (e.q && e.q != "undefined") { //扫码进入
				console.log(e.q, 'e.q')
				const qrUrl = decodeURIComponent(e.q) // 获取到二维码原始链接内容
				//GetWxMiniProgramUrlParam() 这个方法是解析链接地址中的参数方法
				e = this.GetWxMiniProgramUrlParam(qrUrl); //此处就是我们要获取的参数 json
				console.log(qrUrl, e, 'qrUrl')
				//比如我要得到user_id的值，直接取值即可
				uni.setStorageSync('team_id', e.team_id)
				this.option = uni.getStorageSync('team_id')
			}
		},
		onShow() {
			console.log(uni.getStorageSync('team_id'),'onShow')
		},
		methods: {
			GetWxMiniProgramUrlParam(url) {
				let theRequest = {};
				if (url.indexOf("#") != -1) {
					const str = url.split("#")[1];
					const strs = str.split("&");
					for (let i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
					}
				} else if (url.indexOf("?") != -1) {
					const str = url.split("?")[1];
					const strs = str.split("&");
					for (let i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
					}
				}
				return theRequest;
			},
			//提交
			confirm() {
				if (!this.name) {
					this.$wanlshop.msg('请输入姓名');
					return;
				}
				if (!/^1[0-9]{10,10}$/.test(this.mobile)) { // 1.0.2升级
					this.$wanlshop.msg('请输入正确的手机号码');
					return;
				}
				console.log(uni.getStorageSync('team_id'),'team_id')
				uni.request({
					url: '/wanlshop/user/bindTeam',
					method: 'POST',
					data: {
						team_id: uni.getStorageSync('team_id')?uni.getStorageSync('team_id'):'',
						name: this.name,
						mobile: this.mobile
					},
					success: res => {
						console.log(res.res.code, 'dd')
						uni.showToast({
							title: res.msg,
							mask: true,
							duration: 1000
						})
						if(res.res.code == 1){
							setTimeout(()=>{
								this.$wanlshop.to('/pages/home', 'none', 0);
							},1500)
						}
					}
				});
			}
		}
	}
</script>

<style>
	.wanl-bg-orange {
		background: #252525 !important;
	}

	.cu-form-group input {
		text-align: right;
	}

	.cu-form-group {
		padding: 0 25rpx;
	}

	/* 1.1.5升级 */
	.cu-form-group.area {
		position: relative;
	}

	.cu-form-group.area .click {
		position: absolute;
		z-index: 99;
		right: 0;
		left: 0;
		top: 0;
		bottom: 0;
	}

	.cu-form-group .title {
		min-width: calc(4em + 15px);
		font-size: 26rpx;
	}

	.cu-form-group input,
	.cu-form-group textarea {
		font-size: 26rpx;
	}

	.cu-btn.lg {
		font-size: 32rpx;
		height: 86rpx;
	}

	.tipsScroll {
		width: 100%;
		height: 500rpx;
		padding: 0 50rpx;
	}

	.tipsScroll .item {
		margin: 25rpx 0;
	}

	.tipsScroll .item view {
		color: #B8B8B8;
		font-size: 22rpx;
	}

	.tipsScroll .item text {
		color: #333;
	}
</style>